/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * DescripteurManage.java
 *
 * Created on 31 mai 2011, 11:19:29
 */
package cbrtator;

import cbrtator.Descripteur.BoolDescripteur;
import cbrtator.Descripteur.NumDescripteur;
import cbrtator.Descripteur.StringDescripteur;
import cbrtator.Descripteur.SymbolicDescryteur;
import java.util.ArrayList;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import org.jdesktop.application.Action;
import rapc.cas;
import rapc.descripteur;

/**
 *
 * @author rikoukiki
 */
public class DescripteurManage extends javax.swing.JPanel {

    private  ArrayList<descripteur> ldescripteur;
    private int idDesc;
    private ArrayList<JTextField> attributs;
    /** Creates new form DescripteurManage */
    public DescripteurManage( ArrayList<descripteur> ldescripteur )
    {
        this.ldescripteur = ldescripteur;
        attributs = new ArrayList<JTextField>();
        idDesc = 0;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Contentdesctipteur = new javax.swing.JPanel();
        affichageCas = new javax.swing.JPanel();
        precedant = new java.awt.Button();
        suivant = new java.awt.Button();
        navigatedescripteur = new javax.swing.JPanel();
        BSymobolic = new javax.swing.JButton();
        Bchaine = new javax.swing.JButton();
        Bnumerique = new javax.swing.JButton();
        Bbool = new javax.swing.JButton();
        PcontentDescriptor = new javax.swing.JPanel();

        setName("Form"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(cbrtator.CbrtatorApp.class).getContext().getResourceMap(DescripteurManage.class);
        Contentdesctipteur.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("Contentdesctipteur.border.title"))); // NOI18N
        Contentdesctipteur.setName("Contentdesctipteur"); // NOI18N

        affichageCas.setName("affichageCas"); // NOI18N

        javax.swing.GroupLayout affichageCasLayout = new javax.swing.GroupLayout(affichageCas);
        affichageCas.setLayout(affichageCasLayout);
        affichageCasLayout.setHorizontalGroup(
            affichageCasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 345, Short.MAX_VALUE)
        );
        affichageCasLayout.setVerticalGroup(
            affichageCasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 425, Short.MAX_VALUE)
        );

        precedant.setActionCommand(resourceMap.getString("precedant.actionCommand")); // NOI18N
        precedant.setLabel(resourceMap.getString("precedant.label")); // NOI18N
        precedant.setName("precedant"); // NOI18N
        precedant.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                precedantActionPerformed(evt);
            }
        });

        suivant.setActionCommand(resourceMap.getString("suivant.actionCommand")); // NOI18N
        suivant.setLabel(resourceMap.getString("suivant.label")); // NOI18N
        suivant.setName("suivant"); // NOI18N
        suivant.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                suivantActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout ContentdesctipteurLayout = new javax.swing.GroupLayout(Contentdesctipteur);
        Contentdesctipteur.setLayout(ContentdesctipteurLayout);
        ContentdesctipteurLayout.setHorizontalGroup(
            ContentdesctipteurLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ContentdesctipteurLayout.createSequentialGroup()
                .addComponent(precedant, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 243, Short.MAX_VALUE)
                .addComponent(suivant, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(ContentdesctipteurLayout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(affichageCas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(12, 12, 12))
        );
        ContentdesctipteurLayout.setVerticalGroup(
            ContentdesctipteurLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, ContentdesctipteurLayout.createSequentialGroup()
                .addComponent(affichageCas, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(ContentdesctipteurLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(precedant, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(suivant, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        navigatedescripteur.setBorder(javax.swing.BorderFactory.createTitledBorder("Ajouter descipteur"));
        navigatedescripteur.setName("navigatedescripteur"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(cbrtator.CbrtatorApp.class).getContext().getActionMap(DescripteurManage.class, this);
        BSymobolic.setAction(actionMap.get("addSymbolic")); // NOI18N
        BSymobolic.setText(resourceMap.getString("BSymobolic.text")); // NOI18N
        BSymobolic.setName("BSymobolic"); // NOI18N

        Bchaine.setAction(actionMap.get("addString")); // NOI18N
        Bchaine.setText(resourceMap.getString("Bchaine.text")); // NOI18N
        Bchaine.setName("Bchaine"); // NOI18N

        Bnumerique.setAction(actionMap.get("addNUm")); // NOI18N
        Bnumerique.setText(resourceMap.getString("Bnumerique.text")); // NOI18N
        Bnumerique.setName("Bnumerique"); // NOI18N

        Bbool.setAction(actionMap.get("addbool")); // NOI18N
        Bbool.setText(resourceMap.getString("Bbool.text")); // NOI18N
        Bbool.setName("Bbool"); // NOI18N

        PcontentDescriptor.setName("PcontentDescriptor"); // NOI18N

        javax.swing.GroupLayout PcontentDescriptorLayout = new javax.swing.GroupLayout(PcontentDescriptor);
        PcontentDescriptor.setLayout(PcontentDescriptorLayout);
        PcontentDescriptorLayout.setHorizontalGroup(
            PcontentDescriptorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 272, Short.MAX_VALUE)
        );
        PcontentDescriptorLayout.setVerticalGroup(
            PcontentDescriptorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 430, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout navigatedescripteurLayout = new javax.swing.GroupLayout(navigatedescripteur);
        navigatedescripteur.setLayout(navigatedescripteurLayout);
        navigatedescripteurLayout.setHorizontalGroup(
            navigatedescripteurLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, navigatedescripteurLayout.createSequentialGroup()
                .addGroup(navigatedescripteurLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(PcontentDescriptor, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(navigatedescripteurLayout.createSequentialGroup()
                        .addComponent(Bbool)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE)
                        .addComponent(Bnumerique)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(Bchaine)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(BSymobolic)
                .addGap(101, 101, 101))
        );
        navigatedescripteurLayout.setVerticalGroup(
            navigatedescripteurLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, navigatedescripteurLayout.createSequentialGroup()
                .addComponent(PcontentDescriptor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(navigatedescripteurLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Bchaine)
                    .addComponent(Bnumerique)
                    .addComponent(Bbool)
                    .addComponent(BSymobolic)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Contentdesctipteur, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(navigatedescripteur, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(navigatedescripteur, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(Contentdesctipteur, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void precedantActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_precedantActionPerformed
        // TODO add your handling code here:
        
        affichageCas.removeAll();
        if (idDesc >= 0){
            JLabel  lab = new JLabel("Descripteur n°"+idDesc);
            affichageCas.add(lab);
            lab.setBounds(5,10,(int) (affichageCas.getWidth()*0.5), 10);
            descripteur c = ldescripteur.get(idDesc);

            JLabel comp = new JLabel("Nom : ");
            comp.setBounds(5,25,(int) (affichageCas.getWidth()*0.65), 25);
            affichageCas.add(comp);

            JTextField mp = new JTextField(c.getNom());
            mp.setBounds((int) (affichageCas.getWidth()-(affichageCas.getWidth()*0.3)),25,(int) (affichageCas.getWidth()*0.3), 25);
            affichageCas.add(mp);

            comp = new JLabel("Type : ");
            comp.setBounds(5,50,(int) (affichageCas.getWidth()*0.65), 25);
            affichageCas.add(comp);

            mp = new JTextField(c.getType());
            mp.setBounds((int) (affichageCas.getWidth()-(affichageCas.getWidth()*0.3)),50,(int) (affichageCas.getWidth()*0.3), 25);
            affichageCas.add(mp);


            comp = new JLabel("Poids : ");
            comp.setBounds(5,75,(int) (affichageCas.getWidth()*0.65), 25);
            affichageCas.add(comp);

            mp = new JTextField( ""+c.getPoids() );
            mp.setBounds((int) (affichageCas.getWidth()-(affichageCas.getWidth()*0.3)),75,(int) (affichageCas.getWidth()*0.3), 25);
            affichageCas.add(mp);
            attributs.add(mp);
            
            comp = new JLabel("Explication : ");
            comp.setBounds(5,100,(int) (affichageCas.getWidth()*0.65), 25);
            affichageCas.add(comp);

            mp = new JTextField( c.getExplication() );
            mp.setBounds((int) (affichageCas.getWidth()-(affichageCas.getWidth()*0.3)),100,(int) (affichageCas.getWidth()*0.3), 25);
            affichageCas.add(mp);
            attributs.add(mp);

            comp = new JLabel("Id Cas : ");
            comp.setBounds(5,125,(int) (affichageCas.getWidth()*0.65), 25);
            affichageCas.add(comp);

            mp = new JTextField(c.getCaseId() );
            mp.setBounds((int) (affichageCas.getWidth()-(affichageCas.getWidth()*0.3)),125,(int) (affichageCas.getWidth()*0.3), 25);
            affichageCas.add(mp);
            attributs.add(mp);
            
            if (idDesc > 0) idDesc--;

        }
            /*affichage du cas dans le panel*/
            affichageCas.repaint();
}//GEN-LAST:event_precedantActionPerformed

        private void suivantActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_suivantActionPerformed
            // TODO add your handling code here:
          affichageCas.removeAll();
          attributs.clear();

          if (idDesc < ldescripteur.size()){
            JLabel  lab = new JLabel("Descripteur n°"+idDesc);
            affichageCas.add(lab);
            lab.setBounds(5,10,(int) (affichageCas.getWidth()*0.5), 10);
            descripteur c = ldescripteur.get(idDesc);

            JLabel comp = new JLabel("Nom : ");
            comp.setBounds(5,25,(int) (affichageCas.getWidth()*0.65), 25);
            affichageCas.add(comp);

            JTextField mp = new JTextField(c.getNom());
            mp.setBounds((int) (affichageCas.getWidth()-(affichageCas.getWidth()*0.3)),25,(int) (affichageCas.getWidth()*0.3), 25);
            affichageCas.add(mp);

            comp = new JLabel("Type : ");
            comp.setBounds(5,50,(int) (affichageCas.getWidth()*0.65), 25);
            affichageCas.add(comp);

            mp = new JTextField(c.getType());
            mp.setBounds((int) (affichageCas.getWidth()-(affichageCas.getWidth()*0.3)),50,(int) (affichageCas.getWidth()*0.3), 25);
            affichageCas.add(mp);


            comp = new JLabel("Poids : ");
            comp.setBounds(5,75,(int) (affichageCas.getWidth()*0.65), 25);
            affichageCas.add(comp);

            mp = new JTextField( ""+c.getPoids() );
            mp.setBounds((int) (affichageCas.getWidth()-(affichageCas.getWidth()*0.3)),75,(int) (affichageCas.getWidth()*0.3), 25);
            affichageCas.add(mp);
            attributs.add(mp);

            comp = new JLabel("Explication : ");
            comp.setBounds(5,100,(int) (affichageCas.getWidth()*0.65), 25);
            affichageCas.add(comp);

            mp = new JTextField( c.getExplication() );
            mp.setBounds((int) (affichageCas.getWidth()-(affichageCas.getWidth()*0.3)),100,(int) (affichageCas.getWidth()*0.3), 25);
            affichageCas.add(mp);
            attributs.add(mp);

            comp = new JLabel("Id Cas : ");
            comp.setBounds(5,125,(int) (affichageCas.getWidth()*0.65), 25);
            affichageCas.add(comp);

            mp = new JTextField(c.getCaseId() );
            mp.setBounds((int) (affichageCas.getWidth()-(affichageCas.getWidth()*0.3)),125,(int) (affichageCas.getWidth()*0.3), 25);
            affichageCas.add(mp);
            attributs.add(mp);

            if (idDesc+1 < ldescripteur.size()) idDesc++;
        }
           affichageCas.repaint();
}//GEN-LAST:event_suivantActionPerformed

    @Action
    public void addbool() {
        
     this.PcontentDescriptor.removeAll();    
     BoolDescripteur fenetre = new BoolDescripteur(ldescripteur);
      
      
      this.PcontentDescriptor.add(fenetre);
       
       fenetre.setBounds(
               0
               ,0
               ,PcontentDescriptor.getWidth()
               ,PcontentDescriptor.getHeight());
      
       this.PcontentDescriptor.updateUI();
        
       System.out.println(CbrtatorView.Reptravail);
    }
    
        @Action
    public void addNUm() {
        
     this.PcontentDescriptor.removeAll();    
     NumDescripteur fenetre = new NumDescripteur(ldescripteur);
      
      
      this.PcontentDescriptor.add(fenetre);
       
       fenetre.setBounds(
               0
               ,0
               ,PcontentDescriptor.getWidth()
               ,PcontentDescriptor.getHeight());
      
       this.PcontentDescriptor.updateUI();
        
        
    }
        
   @Action
    public void addString() {
        
     this.PcontentDescriptor.removeAll();    
     StringDescripteur fenetre = new StringDescripteur(ldescripteur);      
      
      this.PcontentDescriptor.add(fenetre);
       
       fenetre.setBounds(
               0
               ,0
               ,PcontentDescriptor.getWidth()
               ,PcontentDescriptor.getHeight());
      
       this.PcontentDescriptor.updateUI();        
        
    }
   
    @Action
    public void addSymbolic(){
        
     JOptionPane.showMessageDialog(this, "Pas implémenté, désolé.. ");   
     /*this.PcontentDescriptor.removeAll();    
     SymbolicDescryteur fenetre = new SymbolicDescryteur();      
      
      this.PcontentDescriptor.add(fenetre);
       
       fenetre.setBounds(
               0
               ,0
               ,PcontentDescriptor.getWidth()
               ,PcontentDescriptor.getHeight());
      
       this.PcontentDescriptor.updateUI();       
       */
              
    }  
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BSymobolic;
    private javax.swing.JButton Bbool;
    private javax.swing.JButton Bchaine;
    private javax.swing.JButton Bnumerique;
    private javax.swing.JPanel Contentdesctipteur;
    private javax.swing.JPanel PcontentDescriptor;
    private javax.swing.JPanel affichageCas;
    private javax.swing.JPanel navigatedescripteur;
    private java.awt.Button precedant;
    private java.awt.Button suivant;
    // End of variables declaration//GEN-END:variables
}
